package connection

import (
	"cache-go/lib/sync/wait"
	"net"
)

type Connection struct {
	conn        net.Conn
	sendingData wait.Wait
}

func NewConn(conn net.Conn) *Connection {
	return &Connection{
		conn: conn,
	}
}

func (c *Connection) Write(b []byte) (int, error) {
	if len(b) == 0 {
		return 0, nil
	}
	c.sendingData.Add(1)
	defer func() {
		c.sendingData.Done()
	}()
	return c.conn.Write(b)
}

func (c *Connection) Close() error {
	return c.conn.Close()
}

func (c *Connection) RemoteAddr() string {
	return c.conn.RemoteAddr().String()
}
